package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.Excaption.MyExcaption;
import com.qf.domain.Questions;
import com.qf.mapper.QuestionsMapper;
import com.qf.service.QuestionsService;
import com.qf.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class QuestionsServiceimpl implements QuestionsService {
    @Autowired
    private QuestionsMapper questionsMapper;
    @Override
    public List<Questions> selectAll(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<Questions> list=questionsMapper.selectAll(page,size);
        PageInfo<Questions> pageInfo=new PageInfo<>(list);
        return list;
    }

    @Override
    public int insertadd(Questions questions) {
        int i=questionsMapper.insertadd(questions);
        if (i!=1){
            throw new MyExcaption("查询失败",500);
        }else {
            return i;
        }


    }
    @Transactional
    @Override
    public int update(Integer id) {
        if (id!=null){
            Questions questions=questionsMapper.selectid(id);
            int q=questionsMapper.update(questions.getAnswerCount()+1,id);
            if (q!=1){
                throw new MyExcaption("更新失败",500);

            }
            return q;
        }else {
            throw new MyExcaption("更新失败",500);
        }

    }
}
